package com.llb666.shop.order.infrastructure.persistence;

import com.llb666.shop.order.domain.entity.OrderItems;
import com.llb666.shop.order.domain.repository.OrderItemsRepository;
import com.llb666.shop.order.infrastructure.conver.OrderItemsCvt;
import com.llb666.shop.order.infrastructure.mapper.OrderItemsMapper;
import com.llb666.shop.order.infrastructure.po.OrderItemsPo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 订单商品明细仓储层.
 *
 * @author llb666
 */
@Repository
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class OrderItemsRepositoryImpl implements OrderItemsRepository {

    private final OrderItemsMapper orderItemsMapper;

    /**
     * 查询代办订单.
     *
     * @param orderId 订单id
     * @return 订单列表
     */
    @Override
    public List<OrderItems> queryPendingComment(String orderId) {
        Example example = new Example(OrderItemsPo.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("orderId", orderId);
        return OrderItemsCvt.INSTANCE.po2doList(orderItemsMapper.selectByExample(example));
    }

    /**
     * 新增订单明细.
     * @param subOrderItem 订单商品
     */
    @Override
    public void insert(OrderItems subOrderItem) {
        orderItemsMapper.insert(OrderItemsCvt.INSTANCE.do2po(subOrderItem));
    }

}
